﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Saxxon.LibDoomSharp
{
    public class WadDirectoryEntry : SerializableBase
    {
        /// <summary>
        /// Length in bytes of one entry.
        /// </summary>
        public const int ENTRY_LENGTH = 16;

        /// <summary>
        /// Length in bytes of the name.
        /// </summary>
        public const int NAME_LENGTH = 8;

        /// <summary>
        /// Length in bytes of the data.
        /// </summary>
        public Int32 Length;

        /// <summary>
        /// Offset in bytes of the data.
        /// </summary>
        public Int32 Offset;

        /// <summary>
        /// Entry name.
        /// </summary>
        public string Name;

        /// <summary>
        /// Read a WadDirectoryEntry. Length is ignored.
        /// </summary>
        protected override void Read(Stream stream, int length)
        {
            DataReader reader = GetReader(stream);
            this.Offset = reader.ReadInt32();
            this.Length = reader.ReadInt32();
            this.Name = reader.ReadString(NAME_LENGTH);
        }

        /// <summary>
        /// Write a WadDirectoryEntry.
        /// </summary>
        protected override void Write(Stream stream)
        {
            DataWriter writer = GetWriter(stream);
            writer.WriteInt32(this.Offset);
            writer.WriteInt32(this.Length);
            writer.WriteString(this.Name, NAME_LENGTH);
        }
    }
}
